﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RazorEngine;
using RazorEngine.Templating; // For extension methods.
namespace CYZH.Common
{
    public class MapFileUtils
    {
        
        public static string GenMapFile(string alg,string strextents, string layername)
        {
            //string fileparam = Path.GetFileNameWithoutExtension(tiffile);
            string saveFile = FileOper.GenRasterMapFilePath(layername);
            string unixfile = saveFile.Replace('\\', '/');
            string tmplPath = ConfigHelper.BASE_PATH() + "TemplateFile\\"+alg+"_Map.tmpl";
            string template = System.IO.File.ReadAllText(tmplPath, System.Text.Encoding.UTF8);
            string dataPath ="./"+ alg;
             var result =
                Engine.Razor.RunCompile(template, alg+"templateKey", null, new { LayerName = layername, DataPath=dataPath, Extents = strextents, TiffFile = layername + ".tif", MapFile = unixfile });

            System.IO.File.WriteAllText(saveFile, result, System.Text.Encoding.UTF8);

            return saveFile;
        }
       
    }
}
